package com.shadow.disnet.netty.client;

import com.shadow.disnet.netty.ILog;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyClientOutBoundHandler extends ChannelOutboundHandlerAdapter implements ILog {

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {

        info("出站处理器添加通道");
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {

        info("出站处理器移除通道");
    }

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        super.write(ctx,msg,promise);
        info("出站处处理器发送消息: %s",msg);
    }

    @Override
    public void read(ChannelHandlerContext ctx) throws Exception {
        super.read(ctx);
        info("出站处理器读取消息");
    }

    @Override
    public Logger getLogger() {
        return LoggerFactory.getLogger(this.getClass());
    }

    @Override
    public String toString() {
        return "出站处理器";
    }
}